package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class Practice10HistogramView extends View {

    private Paint paint;

    //内圆半径
    private float nRadius;

    //外圆半径
    private float wRadius;

    //圆心 x轴坐标
    private float centerRadiusX;
    //圆心 y轴坐标
    private float centerRadiusY;

    public Practice10HistogramView(Context context) {
        super(context);
    }

    public Practice10HistogramView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice10HistogramView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (paint == null) {
            paint = new Paint();
        }
        float width = getWidth();

        float height = getHeight();

        float strokeWidth = 70f;

        wRadius = width / 3 + strokeWidth / 2;

        nRadius = width / 4;

        centerRadiusY = height / 2;

        centerRadiusX = width / 2;

        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        canvas.drawCircle(centerRadiusX, centerRadiusY, nRadius, paint);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.TRANSPARENT);
        paint.setAlpha(30);
        paint.setStrokeWidth(strokeWidth);
        canvas.drawCircle(centerRadiusX, centerRadiusY, wRadius, paint);


        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(strokeWidth);
        paint.setColor(Color.RED);
        canvas.drawArc(centerRadiusX - wRadius, centerRadiusY - wRadius, centerRadiusX + wRadius, centerRadiusY + wRadius, 0, -80, false, paint);
        paint.setStrokeWidth(strokeWidth - 5);
        paint.setColor(Color.WHITE);
        canvas.drawArc(centerRadiusX - wRadius, centerRadiusY - wRadius, centerRadiusX + wRadius, centerRadiusY + wRadius, 0, -80, false, paint);


        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(strokeWidth);
        paint.setColor(Color.RED);
        canvas.drawArc(centerRadiusX - wRadius, centerRadiusY - wRadius, centerRadiusX + wRadius, centerRadiusY + wRadius, 90, 90, false, paint);
        paint.setStrokeWidth(strokeWidth - 5);
        paint.setColor(Color.WHITE);
        canvas.drawArc(centerRadiusX - wRadius, centerRadiusY - wRadius, centerRadiusX + wRadius, centerRadiusY + wRadius, 90, 90, false, paint);




        canvas.save();
        canvas.translate(centerRadiusX, centerRadiusY);
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.BLACK);
        for (int i = 0; i < 36; i++) {
            canvas.drawText(i + "--", width / 3 + strokeWidth / 2, 0, paint);
//            canvas.drawCircle(width / 3 + strokeWidth / 2, 0, 5, paint);
            canvas.rotate(10);
        }
        canvas.restore();

        canvas.save();
        canvas.translate(centerRadiusX, centerRadiusY);
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        canvas.drawCircle(wRadius, 0, strokeWidth / 2, paint);
        canvas.restore();

        //画弧线
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        canvas.drawArc(centerRadiusX - wRadius, centerRadiusY - wRadius, centerRadiusX + wRadius, centerRadiusY + wRadius, -5, 10, true, paint);

        //平移坐标原点到圆心处

        //
//        float angel = 360f / 50;
//        //根据角度获取圆上的坐标
//        double x1 = width / 2 + (width / 3 + strokeWidth / 2) * Math.cos(angel * 3.14 / 180);
//        double y1 = height / 2 + width / 3 + (width / 3 + strokeWidth / 2) * Math.cos(angel * 3.14 / 180);
//        Log.e("aaaa",x1+"--"+y1);
//
//        paint.setStyle(Paint.Style.FILL);
//        paint.setColor(Color.BLUE);
//
//        canvas.drawCircle((float) x1,(float) y1,strokeWidth/2,paint);


//        综合练习
//        练习内容：使用各种 Canvas.drawXXX() 方法画直方图
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        float x = event.getX();
        float y = event.getY();
        float downX;
        float downY;
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                downX = x;
                downY = y;
                //计算角度
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
        }
        return true;
    }

    private void degree(float x, float y) {

    }
}
